package com.whl.sm.service.impl.system;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.whl.sm.mapper.system.CommunityMapper;
import com.whl.sm.model.system.Community;
import com.whl.sm.service.system.CommunityService;
import com.whl.sm.service.system.OrgUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wuhaolun
 * @since 2021-10-09
 */
@Service
public class CommunityServiceImpl extends ServiceImpl<CommunityMapper, Community> implements CommunityService {

    @Autowired
    private OrgUserService orgUserService;

    @Override
    @Transactional(propagation= Propagation.REQUIRED)
    public int update(Community community) {
        int result;
        community.setOperator(orgUserService.getCurrentUserId());
        if (StringUtils.isNotBlank(community.getId())){
            getBaseMapper().updateById(community);
            result=1;
        }
        else {
            getBaseMapper().insert(community);
            result=2;
        }
        return result;
    }
}
